#include <iostream>

using namespace std;

const int N = 5010;
int f[N][N];
string s, t;

int main()
{
	while(cin >> s >> t)
	{
		for(int i = 1; i <= s.size(); i++)
		{
			for(int j = 1; j <= t.size(); j++)
			{
				if(s[i - 1] == t[j - 1])
				{
					f[i][j] = f[i - 1][j - 1] + 1;;
				}
				else
				{
					f[i][j] = max(f[i - 1][j], f[i][j - 1]);
				}
			}
		}
	
		cout << f[s.size()][t.size()] << endl;
	}

	
	return 0;
}
